package cn.com.hori.cms.controller;

import cn.com.hori.cms.entities.ColumnAdmin;
import cn.com.hori.cms.model.ColumnTreeNode;
import cn.com.hori.cms.model.CommonResponse;
import cn.com.hori.cms.service.ColumnService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 栏目管理 contorller
 *
 * @author 刘艺
 * @date 2018/3/8 14:53
 */
@RestController
@RequestMapping("/smc/column")
public class ColumnController {
    private static Logger logger = LoggerFactory.getLogger(ColumnController.class);


    @Autowired
    private ColumnService columnService;

    @GetMapping("/getTree")
    public CommonResponse treeColumn(@RequestParam String managerId) {
        ColumnTreeNode tree = columnService.getTree();
        return new CommonResponse<>(tree);
    }

    @GetMapping("/getColumn")
    public CommonResponse getColumn(@RequestParam String columnId) {
        ColumnAdmin column = columnService.getColumn(columnId);
        return new CommonResponse<>(column);
    }


    @PostMapping("/updateColumn")
    public CommonResponse updateColumn(@RequestBody ColumnAdmin columnAdmin) {
        return new CommonResponse<>(columnService.updateColumn(columnAdmin));
    }

    @PostMapping("/deleteColumn")
    public CommonResponse deleteColumn(@RequestBody ColumnAdmin columnAdmin) {
        String msg = columnService.deleteColumn(columnAdmin);
        if (msg == "success"){
            return new CommonResponse<>();
        }else {
            CommonResponse commonResponse = new CommonResponse();
            commonResponse.setCode(CommonResponse.OTHER_FAIL_CODE);
            commonResponse.setMsg(msg);
            return commonResponse;
        }

    }
}
